package rsb212.num23.ysh.d1130.chap06;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Tools {


    //获取不及格学生
    public static List<Student> getScore(List<Student> list){
        List<Student> stus =new ArrayList<>();
        Iterator<Student> iterator=list.iterator();
        while(iterator.hasNext()){
            Student stu=iterator.next();
            if (stu.getScore()<60){
                stus.add(stu);

            }
        }
        return stus;
    }

    

    //平均分
    public static double getAvg(List<Student> stuList){
        //所有成绩的和
        double sum=0;
        for (Student s : stuList) {
            sum=sum+s.getScore();
        }
        return sum/stuList.size();
    }
    //最高分
    public  static Student getMax(List<Student> list){
        Iterator<Student> it=list.iterator();
        Student stuMax=it.next();//假设第一个学生就是最高分的学生
        while (it.hasNext()){
            Student stu=it.next();
            if(stu.getScore()>stuMax.getScore()){
                stuMax=stu;
            }
        }
        return stuMax;
    }
    //获得不及格学生
    public static List<Student> getScore(List<Student> list,double x,double y){
        List<Student> stus=new ArrayList<>();
        Iterator<Student> it = list.iterator();
        while (it.hasNext()){
            Student stu=it.next();
            if (stu.getScore()>=x && stu.getScore()<y){
                stus.add(stu);
            }
        }
        return stus;
    }



}

